//
//  OpenTimeTableViewCell.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/4/26.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit
protocol DefinTimeDelegate:class {
    func defineTime(definBool:Bool) -> Void
}
class OpenTimeTableViewCell: BaseTableViewCell {
    weak var delegate:DefinTimeDelegate?
    
    lazy var allTimeBtn:UIButton = {
       let button = UIButton()
        button.layer.borderColor = kThemeColor.cgColor
        button.layer.borderWidth = 0.5
        button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        button.addTarget(self, action: #selector(allBtnAction), for: UIControlEvents.touchUpInside)
        button.setTitleColor(kThemeColor, for: UIControlState.normal)
        button.setTitle(kText("任何时间"), for: UIControlState.normal)
        button.layer.cornerRadius = 14
        button.layer.masksToBounds = true
       return button
    }()
    
    lazy var definedBtn:UIButton =  {
        let button = UIButton()
        button.layer.borderColor = UIColor(hexStr:"#c0c0c0").cgColor
        button.layer.borderWidth = 0.5
        button.layer.cornerRadius = 14
        button.layer.masksToBounds = true
        button.addTarget(self, action: #selector(definBtnAction), for: UIControlEvents.touchUpInside)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        button.setTitleColor(UIColor(hexStr:"#9b9b9b"), for: UIControlState.normal)
        button.setTitle(kText("自定义"), for: UIControlState.normal)
        return button
    }()
    override func setUpUI() {
        super.setUpUI()
        self.nameLabel.text = kText("开放时间")
        self.nameLabel.font = UIFont.systemFont(ofSize: 12)
        self.contentView.addSubview(allTimeBtn)
        allTimeBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-134)
            make.width.equalTo(71)
            make.height.equalTo(28)
            make.centerY.equalToSuperview()
        }
        
        self.contentView.addSubview(definedBtn)
        definedBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-47)
            make.width.equalTo(71)
            make.height.equalTo(28)
            make.centerY.equalToSuperview()
        }
        
    }
    
    @objc func allBtnAction() ->Void {
        self.changeStyle(defineBool: false)
       self.selectDefine(defineBool: false)
    }
    @objc func definBtnAction() -> Void {
        self.changeStyle(defineBool: true)
        self.selectDefine(defineBool: true)
    }
    func selectDefine(defineBool:Bool) {
        if delegate != nil {
            self.delegate!.defineTime(definBool: defineBool)
        }
    }
    
    func changeStyle(defineBool:Bool) -> Void {
        if defineBool {
            definedBtn.layer.borderColor = kThemeColor.cgColor
            definedBtn.setTitleColor(kThemeColor, for: UIControlState.normal)
            allTimeBtn.layer.borderColor = UIColor(hexStr:"#c0c0c0").cgColor
            allTimeBtn.setTitleColor(UIColor(hexStr:"#c0c0c0"), for: UIControlState.normal)
        }else {
            allTimeBtn.layer.borderColor = kThemeColor.cgColor
            allTimeBtn.setTitleColor(kThemeColor, for: UIControlState.normal)
            definedBtn.layer.borderColor = UIColor(hexStr:"#c0c0c0").cgColor
            definedBtn.setTitleColor(UIColor(hexStr:"#c0c0c0"), for: UIControlState.normal)
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
